package beans.factory.support;

import beans.BeansException;
import beans.factory.config.BeanDefinition;

/**
 * @Author: Take-off
 * @Description: TODO 实现默认bean创建的抽象bean工厂超类
 * @Date: 2022/12/12 10:18 AM
 * @Version: 1.0
 **/
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }

        registerSingleton(beanName, bean);
        return bean;
    }
}
